package com.chicken.common;

import com.chicken.controller.AdminController;
import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import com.chicken.controller.IndexController;

/**
 * @author zewei.wang
 * @date 2018/4/4.
 */
public class MainConfig extends JFinalConfig{

    @Override
    public void configConstant(Constants me) {
        me.setViewType(ViewType.JSP);
        me.setBaseUploadPath("upload/");
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        me.setBaseViewPath("page/");
        me.add("/index", IndexController.class,"/");
        me.add("/admin", AdminController.class,"/");
    }

    @Override
    public void configEngine(Engine me) {

    }

    @Override
    public void configPlugin(Plugins me) {
        DruidPlugin druidPlugin = MainConfig.createDruidPlugin();
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        _MappingKit.mapping(arp);
        arp.setShowSql(true);
        me.add(druidPlugin);
        me.add(arp);

    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {
    }

    public static DruidPlugin createDruidPlugin(){
        PropKit.use("jdbc.properties");
        return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
    }

}
